<template>
	<!-- 工单投产 -->
	<div>
		<v-card>
			<v-container row class="text-subtitle-1 d-flex justify-center  align-left">
				<v-row class="mt-2">
					<v-col cols="12" sm="3" md="2">
						<v-text-field label="项目号" v-model="queryChildren.projectCode" placeholder="项目号" dense outlined>
						</v-text-field>
					</v-col>
					<!-- sm="6" md="2" -->
					<v-col cols="12" sm="3" md="2">
						<v-text-field label="项目名称" v-model="queryChildren.projectName" placeholder="项目名称" dense
							outlined>
						</v-text-field>
					</v-col>
					<v-col cols="12" sm="3" md="2">
						<v-text-field label="设备名称" v-model="queryChildren.equipmentName" placeholder="设备名称" dense
							outlined>
						</v-text-field>
					</v-col>
					<v-col cols="12" sm="2" md="2">
						<v-text-field label="工单号" v-model="queryChildren.childrenCode" placeholder="工单号" dense outlined>
						</v-text-field>
					</v-col>
					<v-col cols="12" sm="3" md="2">
						<v-select v-model="queryChildren.childrenStatus" :items="childrenOrderStatusEnumList" label="状态"
							dense outlined></v-select>
					</v-col>
					<!-- ml-n16 前面加n是间距 -->
					<!-- class="ml-n16 mx-auto" -->
					<v-col cols="12" sm="2" md="2">
						<v-btn depressed color="primary" @click="serach">查询</v-btn>
						<v-btn class="ml-3" depressed color="primary" @click="refreshApps">
							刷新</v-btn>
					</v-col>
				</v-row>


			</v-container>
		</v-card>

		<v-data-table small fixed-header dense
			:headers="childrenHeaderList.filter((val, index, arr) => {return index !==0;})" :items="childrenOrderList"
			item-key="id" class="text-no-wrap elevation-1" show-select :loading="childrenOrderLoading"
			:options.sync="childrenOrderOptions" :footer-props="vuetifyDefaultPage"
			:server-items-length="childrenOrderTotalCount" @toggle-select-all="childrenTableSelectAll"
			@input="checkChildrenOrderEvent">
			<template v-slot:item.picurl="{ item }">
				<a @click="openLookPicsClick(item.picurl)">查看文件</a></td>
			</template>
			<template v-slot:item.isinpruduction="{item}">
				<td>
					<a v-if="item.isinpruduction==1" style="color: #67C23A;">是</a>
					<a v-else>否</a>
				</td>
			</template>
			<template v-slot:item.isprint="{item}">
				<td>
					<a v-if="item.isprint==1" style="color: #67C23A;">是</a>
					<a v-else>否</a>
				</td>
			</template>
			<!-- 	<td class="text-left">
						<v-btn class="ml-2" small tile color="success" @click="openGYDialog(item)">
							<v-icon small left>
								mdi-pencil
							</v-icon>
							编辑工艺
						</v-btn>
					</td> -->
			<!-- <td class="text-center"><a @click="openGYDialog(item)">查看工艺</a></td> -->
			<!-- <td class="text-center">	<v-btn color="primary" @click="openIntoProductionDialogVisable=true">投产</v-btn></td> -->
			<!-- 	<template v-slot:item="{item}">
				<tr :class="item.isinpruduction?'main':''">
					<td>
						<v-checkbox v-model="item.check" :disabled="item.isinpruduction" style="height:20px;"
							class="mb-5" @click="checkChildrenOrderEvent(item)"></v-checkbox>
					</td>
				
					<td class="text-center">{{ item.code}}</td>
					<td class="text-center">{{ item.piccode }}</td>
					<td class="text-center"><a :href="item.picurl" target="_Blank">查看图纸</a></td>
					<td class="text-center">{{ item.name }}</td>
					<td class="text-center">{{ item.specifications }}</td>
					<td class="text-center">{{ item.model }}</td>
					<td class="text-center">{{ item.material }}</td>
					<td class="text-center">{{ item.singlecount }}</td>
					<td class="text-center">{{ item.totalcount }}</td>
					<td class="text-center">{{ item.unit }}</td>
					<td class="text-center">{{ item.surface_treatment }}</td>
					<td class="text-center">{{ item.process }}</td>
					
					<td class="text-center">{{ item.outinstoragelinkname }}</td>
					<td class="text-center">{{ item.deliverydate }}</td>
					<td class="text-center">{{ item.confirmdate }}</td>
					<td class="text-center">{{ item.typename }}</td>
					<td class="text-center">{{ item.statusname }}</td>
					<td class="text-center">{{ item.company }}</td>
					<td class="text-center">{{ item.description }}</td>
				</tr>
			</template> -->
			<!-- 	<template v-slot:footer>
			<v-banner single-line class="text-left subtitle-1">
				工单总数：{{pageModel.pagination.totalRecords}}
			</v-banner>
		</template> -->
		</v-data-table>

		<v-card class="align-left">
			<v-sheet class="pa-5" color="grey lighten-3">
				<v-btn color="primary" @click="openIntoProductionDialogVisable=true">投产</v-btn>
				<!-- <v-btn color="primary" class="ml-2" @click="openIntoProductionDialogVisable=true">打印</v-btn> -->
				<!-- <v-btn color="primary" @click="openIntoProductionDialogVisable=true">投产</v-btn> -->
				<!-- <v-btn color="primary" @click="openGYDialog(null)" class="ml-3">批量工艺维护</v-btn> -->
			</v-sheet>
			<v-card-text>
				<v-data-table small fixed-header dense :headers="childrenHeaderList"
					:items="currentCheckChildrenOrderList" item-key="code" class="text-no-wrap elevation-1"
					:footer-props="tempvuetifyDefaultPage">
					<template v-slot:item="{item}">
						<tr :style="item.isinpruduction?'background:#aaf5aa;':''">
							<td class="text-center">
								<v-btn color="error" fab small dark icon
									@click="currentCheckChildrenOrderList.splice(currentCheckChildrenOrderList.findIndex(z => z.id == item.id), 1)">
									删除
								</v-btn>
								<v-tooltip right>
									<template v-slot:activator="{ on, attrs }">
										<v-btn color="primary" v-bind="attrs" v-on="on" fab small dark icon
											:disabled="!item.isinpruduction" @click="openPrintDialog(item)">
											打印
										</v-btn>
									</template>
								</v-tooltip>
							</td>
							<td class="text-center">{{ item.code}}</td>
							<td>
								<a v-if="item.isinpruduction==1" style="color: #67C23A;">是</a>
								<a v-else>否</a>
							</td>
							<td>
								<a v-if="item.isprint==1" style="color: #67C23A;">是</a>
								<a v-else>否</a>
							</td>
							<td class="text-center">{{ item.piccode }}</td>
							<td class="text-center"><a :href="item.picurl" target="_Blank">查看图纸</a></td>
							<td class="text-center">{{ item.name }}</td>
							<td class="text-center">{{ item.specifications }}</td>
							<td class="text-center">{{ item.totalcount }}</td>
							<td class="text-center">{{ item.unit }}</td>
							<td class="text-center">{{ item.deliverydate }}</td>
							<td class="text-center">{{ item.typename }}</td>
							<td class="text-center">{{ item.statusname }}</td>
							<td class="text-center">{{ item.description }}</td>
							<td class="text-center">{{ item.temp1 }}</td>

						</tr>
					</template>
				</v-data-table>

			</v-card-text>
		</v-card>
		<!-- <v-row justify="center">
			<v-col cols="8">
				<v-container class="max-width"> -->
		<!-- total-visible:最大可见分页数 -->
		<!-- prev-icon:是用其它图片做上一页的按钮 -->
		<!-- next-icon:是用其它图片做下一页的按钮 -->
		<!-- circle:分页的按钮都是圆的 -->
		<!-- <v-pagination v-model="pageModel.pagination.pageNumber" class="my-4"
						:length="pageModel.pagination.totalPages" :total-visible="7" prev-icon="mdi-menu-left"
						next-icon="mdi-menu-right" circle @input="goPage">
					</v-pagination>
				</v-container>
			</v-col>
		</v-row> -->

		<!-- 投产对话框 -->
		<v-dialog v-model="openIntoProductionDialogVisable" max-width="500px">
			<v-card>
				<v-card-title>
					工单投产
				</v-card-title>

				<v-form ref="form">
					<v-card-text>
						<v-alert class="text-left" type="warning" dark>
							为选中的项拆批，不输入拆批数量则不拆批投产！
						</v-alert>
						<v-text-field label="输入拆批数量" outlined v-model="dialogSplitBatchCount"
							:rules="dialogSplitBacthRule">
						</v-text-field>
					</v-card-text>
					<v-card-actions>
						<v-spacer></v-spacer>
						<v-btn color="primary" text @click="intoProduction">
							投产
						</v-btn>
						<v-btn color="primary" text @click="openIntoProductionDialogVisable = false">
							关闭
						</v-btn>
					</v-card-actions>
				</v-form>
			</v-card>
		</v-dialog>
		<!-- 选择工艺对话框 -->
		<v-dialog v-model="gyDialogVisable" max-width="1300px">
			<v-card class="mx-auto" outlined>
				<v-card-title>
					工艺维护
				</v-card-title>
				<v-card-text>
					<v-row>
						<v-col cols="6">
							<v-alert text color="blue-grey">工单工艺</v-alert>
							<v-alert text dense dark color="indigo" class="text-left">
								可为工单手动添加工艺
								<v-btn class="ml-3" color="primary" @click="openAddOrEditGYDialog()">
									新增工艺
								</v-btn>
							</v-alert>
							<!-- 左侧的工艺列表 -->
							<v-data-table height="450" small fixed-header dense :headers="leftGYHeaderList"
								:items="leftGYDataList" item-key="id" class="text-no-wrap"
								:footer-props="vuetifyDefaultPage">

								<template v-slot:item.order="props">
									<v-edit-dialog large @save="saveGYOrder(props.item)" save-text="更新执行顺序"
										cancel-text="取消">
										<a>
											{{ props.item.order}}
										</a>
										<v-icon small class="mr-2" color="red">
											mdi-pencil
										</v-icon>
										<template v-slot:input>
											<div class="mt-4 text-h6">
												变更执行顺序
											</div>
											<v-text-field :rules="GYOrderRule" v-model="props.item.order" label="执行顺序">
											</v-text-field>
										</template>
									</v-edit-dialog>
								</template>
								<template v-slot:item.actions="{ item }">
									<div>
										<v-btn class="ml-2" small tile color="success"
											@click="openAddOrEditGYDialog(item)" :disabled="item.id==null?false:true">
											<v-icon small left>
												mdi-pencil
											</v-icon>
											编辑
										</v-btn>
										<!-- 删除按钮 -->
										<v-btn small class="ml-2" tile color="red" @click="leftGYDataList.splice(leftGYDataList.findIndex(c => c.code+c.name == item
							.code+item.name), 1)">
											<v-icon small left>
												mdi-delete
											</v-icon>
											删除
										</v-btn>
									</div>
								</template>

							</v-data-table>
						</v-col>
						<v-col cols="6">
							<!-- 右侧的工艺列表 -->
							<v-alert text color="blue-grey">选择标准工艺</v-alert>
							<v-text-field fiexd v-model="searchGYInput" append-icon="mdi-magnify"
								label="输入工艺代码或工艺名称对应内容后，回车" single-line hide-details autocomplete
								@keypress.enter="searchGY"></v-text-field>
							<br />
							<v-data-table height="450" small fixed-header dense :headers="rightGYHeaderList"
								:items="rightGyDataList" class="text-no-wrap" item-key="id" show-select
								:footer-props="vuetifyDefaultPage" @input="selectRightGYEvent">
							</v-data-table>
						</v-col>
					</v-row>
				</v-card-text>
				<v-card-actions>
					<v-spacer></v-spacer>
					<v-btn color="primary" text @click="saveGY">
						确定
					</v-btn>
					<v-btn color="primary" text @click="gyDialogVisable = false">
						关闭
					</v-btn>
				</v-card-actions>
			</v-card>
		</v-dialog>
		<!-- 添加工艺对话框 -->
		<v-dialog v-model="addOrEidtGYDialogVisable" max-width="800px">
			<v-card>
				<v-card-title>
					<span class="text-h5">编辑工艺</span>
				</v-card-title>
				<v-card-text>
					<v-form ref="form" v-model="addOrEditGYModelValid">
						<v-row>
							<v-col cols="12" sm="6" md="4">
								<v-text-field label="工艺代码(必填)" required :rules="addOrEditGYModelCodeRule"
									v-model="addOrEditGYModel.code">
								</v-text-field>
							</v-col>
							<v-col cols="12" sm="6" md="4">
								<v-text-field label="工艺名称(必填)" required :rules="addOrEditGYModelNameRule"
									v-model="addOrEditGYModel.name">
								</v-text-field>
							</v-col>
							<v-col cols="12" sm="6" md="4">
								<v-text-field label="执行顺序" :rules="addOrEditGYModelOrderRule"
									v-model="addOrEditGYModel.order">
								</v-text-field>
							</v-col>
							<v-col cols="12">
								<v-textarea outlined name="input-7-4" label="备注" v-model="addOrEditGYModel.description"
									:value="addOrEditGYModel.description">
								</v-textarea>
							</v-col>
						</v-row>
					</v-form>
				</v-card-text>
				<v-card-actions>
					<v-spacer></v-spacer>
					<v-btn color="blue darken-1" :disabled="!addOrEditGYModelValid" text @click="AddOrEditGY">
						{{isAddOrEditGYModel?'修改':'新增'}}
					</v-btn>
					<v-btn color="blue darken-1" text @click="cancelGY">
						取消
					</v-btn>
				</v-card-actions>
			</v-card>
		</v-dialog>
		<!-- 打印对话框 -->
		<v-dialog v-if="currentPrintSingleModel!=null&&currentPrintSingleModel.childrenOrder!=null"
			v-model="printDialog" max-width="800px">
			<v-card>
				<v-card-title></v-card-title>
				<v-card-text>

					<div class="dayin">
						<div ref="print" id="printProcessCard">
							<table class="tab">
								<tbody class="top-tbody">
									<tr style="height:25px;">
										<td style="width:95px;font-weight:bold">设备名称</td>
										<td style="width:280px;text-align: center;">
											{{currentPrintSingleModel.childrenOrder.name}}
										</td>
										<td style="width:95px;font-weight:bold">工单类型</td>
										<td style="width:95px;font-weight:bold;text-align: center;">
											{{currentPrintSingleModel.childrenOrder.typename}}
										</td>
										<td colspan="1" rowspan="2" style="width: 120px;height: 120px;"><img
												style="width: 120px;height: 120px;"
												:src="currentPrintSingleModel.qrcode" /></td>
									</tr>
									<tr style="height:25px;">
										<td style="width:95px;font-weight:bold">项目名称</td>
										<td style="text-align: center;">
											{{currentPrintSingleModel.childrenOrder.projectname}}
										</td>
										<td style="width:75px;font-weight:bold">项目号</td>
										<td style="width:130px;text-align: center;">
											{{currentPrintSingleModel.childrenOrder.projectcode}}
										</td>

									</tr>
									<tr style="height:25px;">
										<td style="width:75px;font-weight:bold">工单号</td>
										<td style="width:130px;text-align: center;">
											{{currentPrintSingleModel.childrenOrder.code}}
										</td>
										<td style="width:95px;font-weight:bold">交期</td>
										<td style="text-align: center;" colspan="2">
											{{currentPrintSingleModel.childrenOrder.deliverydate|dateFormat}}
										</td>

									</tr>

									<tr>
										<td style="width:95px;font-weight:bold">图号</td>
										<td style="text-align: center;">
											{{currentPrintSingleModel.childrenOrder.piccode}}
										</td>
										<td style="width:95px;font-weight:bold">数量</td>
										<td style="text-align: center;" colspan="2">
											{{currentPrintSingleModel.childrenOrder.totalcount}}
										</td>
									</tr>
								</tbody>
							</table>
							<table class="tab" style="border-top:none;">
								<tbody class="bottom-tbody">
									<tr class="tr-head" style="height:25px;border-bottom:1px solid #000;">
										<td style="font-weight:bold; text-align:center;" colspan="5">物料信息</td>
									</tr>

									<tr class="tr-head" style="height:25px;">
										<td class="td-bold td-center column-1">物料编码</td>
										<td class="td-bold td-center column-2">物料名称</td>
										<td class="td-bold td-center column-3">物料规格</td>
										<td class="td-bold td-center column-5">数量</td>
										<td class="td-bold td-center column-5">单位</td>
									</tr>
									<tr v-for="requestOrder in currentPrintSingleModel.requestOrderList"
										:key="requestOrder.id" class="tr-body" style="height:25px;">
										<td class="td-body-color td-center column-1 column-body-1">
											{{requestOrder.materialcode}}
										</td>
										<td class="td-body-color td-center column-2 column-body-2">
											{{requestOrder.materialname}}
										</td>
										<td class="td-body-color td-center column-3 column-body-3">
											{{requestOrder.materialspecification}}
										</td>
										<td class="td-body-color td-center column-3 column-body-3">
											{{requestOrder.needqty}}
										</td>
										<td class="td-body-color td-center column-5 column-body-5">
											{{requestOrder.unitname}}
										</td>
									</tr>

									<!-- <tr class="tr-head" style="height:25px; ">
										<td style="font-weight:bold; text-align:left" colspan="5">检查项目 共计检查项：
											未检查项：不合格隐患：
										</td>
									</tr>
									<tr class="tr-head" style="height:25px;">
										<td class="td-bold td-center column-1">NO.</td>
										<td class="td-bold td-center" colspan="2">检查内容</td>
										<td class="td-bold td-center column-4">结果</td>
										<td class="td-bold td-center column-5">描述</td>
									</tr> -->
									<!-- <tr class="tr-head">
										<td class="td-bold td-center" colspan="5">
											<pdf ref="pdf" :src="pdfSrc"></pdf>
										</td>
									</tr>
 -->
								</tbody>
							</table>
						</div>
					</div>
				</v-card-text>
				<v-card-actions>
					<v-spacer></v-spacer>
					<div class="no-print">
						<v-btn color="primary" text @click="printContext">打印</v-btn>
						<v-btn color="primary" text @click="close">关闭</v-btn>
					</div>
				</v-card-actions>
			</v-card>
		</v-dialog>
		<showfiledialog :filesModel="fileDialogComment"></showfiledialog>
	</div>
</template>

<script>
	import print from 'print-js'
	import pdf from 'vue-pdf'
	import showfiledialog from '../../comments/ShowFilesDialog.vue'
	export default {
		components: {
			pdf,
			showfiledialog
		},
		name: 'mes_production_putcost',
		data: () => ({
			queryChildren: {
				projectCode: '',
				projectName: '',
				equipmentName: '',
				childrenCode: '',
				childrenStatus: null
			},
			fileDialogComment: {
				dialog: false,
				files: []
			},
			vuetifyDefaultPage: {
				'items-per-page-text': '每页个数',
				'items-per-page-options': [10, 20, 50, 100]
				// 'items-per-page-all-text': '100'
			},
			tempvuetifyDefaultPage: {
				'items-per-page-text': '每页个数',
				'items-per-page-options': [100, 200]
			},
			searchGYInput: '',
			addOrEidtGYDialogVisable: false,
			//工艺对话框
			gyDialogVisable: false,
			//拆批个数
			dialogSplitBatchCount: 0,
			//投产对话框
			openIntoProductionDialogVisable: false,
			paramterEnums: ["WorkOrderChildrenStatus"],
			isShowStatusSelect: false,
			searchSelectChildrenStatus: 20,
			childrenOrderStatusEnumList: [],
			childrenHeaderList: [],
			childrenOrderList: [],
			currentCheckChildrenOrderList: [],
			selectedInputType: null,
			searchInput: null,
			//是否投产 0:未投产 1:已投产
			// isProduction: 0,
			//拆批文本框输入规则
			dialogSplitBacthRule: [
				v => /^[0-9]*$/.test(v) || '请输入合法数字',
				v => v < 100 || '最大不能超出100'
			],
			GYOrderRule: [
				v => /^[0-9]*$/.test(v) || '请输入合法数字'
			],
			rightGYHeaderList: [{
				text: '工艺代码',
				value: 'code'
			}, {
				text: '工艺名称',
				value: 'name'
			}, {
				text: '描述',
				value: 'description'
			}],
			// 右侧工艺源数据
			rightGyDataList: [],
			//右侧选择的工艺数据
			rightSelectGYDataList: [],
			//左侧的工艺信息头
			leftGYHeaderList: [],
			//左侧的工艺数据
			leftGYDataList: [],
			addOrEditGYModel: {},
			addOrEditGYModelCodeRule: [v => !!v || '工艺代码不能为空'],
			addOrEditGYModelNameRule: [v => !!v || '工艺名称不能为空'],
			addOrEditGYModelOrderRule: [v => /^[0-9]*$/.test(v) || '输入合法的执行顺序'],
			addOrEditGYModelValid: true,
			//编辑或新增 工艺对话框 false:新增 true:编辑
			isAddOrEditGYModel: false,
			//子工单页面分页相关信息
			childrenOrderLoading: true,
			childrenOrderTotalCount: 0,
			childrenOrderOptions: {
				//页数
				page: 1,
				//每页行数
				itemsPerPage: 10
			},
			printDialog: false,
			//流程卡
			currentPrintSingleModel: null,
			pdfSrc: 'http://localhost:9866/src/pdffile/073016480144ImagePDF.pdf'
		}),
		created() {
			this.loadEnumList()
			this.getHeader()
			// this.search()
			this.leftGYHeaderList = [{
				text: '操作',
				value: 'actions',
				align: 'center'
			}, {
				text: '执行顺序',
				value: 'order'
			}, ...this.rightGYHeaderList]

			// 有时PDF文件地址会出现跨域的情况,这里最好处理一下
			this.pdfSrc = pdf.createLoadingTask(this.pdfSrc)
		},
		mounted() {
			// this.printContext();
		},
		watch: {
			childrenOrderOptions: {
				handler() {
					this.serach()
				},
				deep: true
			}
		},
		methods: {
			//查看图片
			openLookPicsClick(pathstrs) {
				this.fileDialogComment.dialog = true
				this.fileDialogComment.files = JSON.parse(pathstrs)
			},
			getColor(flag) {
				if (flag) return 'green'
				else return 'red'
			},
			refreshApps() {
				this.searchInput = null
				this.searchSelectChildrenStatus = 20
				this.isShowStatusSelect = false
				this.selectedInputType = 1
				this.search()
			},
			sercarhRadioChange(value) {
				if (value == 5) {
					this.isShowStatusSelect = true
				} else
					this.isShowStatusSelect = false
			},
			searchChildrenSelectChange(item) {
				this.searchInput = null
				this.searchSelectChildrenStatus = item
				this.search()
			},
			loadEnumList() {
				var that = this
				this.$httpRequest({
					url: `MES/MESCommon/GetTypes`,
					method: 'post',
					data: this.paramterEnums
				}).then(function(response) {
					if (response.status == 1) {
						that.childrenOrderStatusEnumList = response.data
					} else {
						that.$message.error('加配置信息失败')
					}
				})
			},
			//选项卡点击事件
			productionItemClick(val) {
				if (val == 0 || val == 1) {
					this.isProduction = val
					this.childrenOrderOptions.page = 1
				}
			},
			refreshApps() {
				this.queryChildren = {
					projectCode: '',
					projectName: '',
					equipmentName: '',
					childrenCode: '',
					childrenStatus: null
				}

				this.childrenOrderOptions = {
					page: 1,
					itemsPerPage: 10
				}
			},
			async serach() {
				this.childrenOrderLoading = true
				this.childrenOrderList = []


				var response = await this.$httpRequest({
					url: `MES/MESProductionInto/LoadChildrenOrderList?
					projectcode=${this.queryChildren.projectCode}&
					projectname=${this.queryChildren.projectName}&
					name=${this.queryChildren.equipmentName}&
					code=${this.queryChildren.childrenCode}&
					status=${this.queryChildren.childrenStatus}&
					pageNumber=${this.childrenOrderOptions.page}&
					pageSize=${this.childrenOrderOptions.itemsPerPage}`,
					method: 'get'
				})

				if (response.status == 1) {
					this.childrenOrderTotalCount = response.data.totalCount.value
					this.childrenOrderList = response.data.childrenList
					this.childrenOrderLoading = false


				} else {
					this.$message.error('加载子工单失败')
				}

			},
			// 投产
			async intoProduction() {
				const checkChildrenIds = this.currentCheckChildrenOrderList.map(c => c.id)
				if (checkChildrenIds.length <= 0) {
					this.$message.warn('请选中需要投产的项目')
					return
				}

				if (!this.$refs.form.validate())
					return

				var response = await this.$httpRequest({
					url: `MES/MESProductionInto/OrderInProduction`,
					method: 'post',
					data: {
						childrenIds: checkChildrenIds,
						splitBatchCount: this.dialogSplitBatchCount
					}
				})

				if (response.status == 1) {
					this.openIntoProductionDialogVisable = false
					this.$message.success(response.info)
					this.currentCheckChildrenOrderList = response.data
					this.serach()

				} else {
					this.$message.error(response.info)
				}
			},
			//子工单选中所有
			childrenTableSelectAll(table) {
				this.childrenOrderList.forEach(r => {
					if (!r.isinpruduction)
						r.check = table.value
				})
			},
			//打开工艺对话框
			openGYDialog(item) {
				this.leftGYDataList = []
				if (item != null) {
					item.check = true
					this.leftGYDataList = item.processCardGYList
				}
				this.gyDialogVisable = true
				this.searchGY()
			},
			//搜索工艺
			searchGY() {
				var that = this
				this.$httpRequest({
					url: `MES/MESProductionInto/LoadGYList?codeorname=${this.searchGYInput}`,
					method: 'get'
				}).then(function(response) {
					if (response.status == 1) {
						that.rightGyDataList = response.data
					} else {
						console.log('加载工艺信息失败')
					}
				})

			},
			//保存工艺顺序
			saveGYOrder(item) {
				this.leftGYDataList.forEach(r => {
					if (r.code == item.code) {
						r.order = item.order
					}
				})
				this.leftGYDataList.sort(function(a, b) {
					return a.order - b.order
				})

			},
			//右侧选中的工艺信息
			selectRightGYEvent(items) {
				var customCreate = this.leftGYDataList.filter(r => r.id == null)
				this.leftGYDataList = items
				if (customCreate.length > 0) {
					customCreate.forEach(r => {
						this.leftGYDataList.push(r)
					})
				}
				var order = 0
				this.leftGYDataList.forEach(r => {
					r.order = ++order
				})
			},
			// 保存所有工艺信息
			saveGY() {
				var checkChildrenList = this.childrenOrderList.filter(r => r.check)
				if (checkChildrenList.length <= 0) {
					that.$message.warn('编辑子工单工艺信息成功')
					return
				}
				if (this.leftGYDataList.length <= 0) {
					that.$message.warn('请选则需要的工艺')
					return
				}
				checkChildrenList.forEach(r => {
					r.processCardGYList = this.leftGYDataList
					r.process = JSON.stringify(this.leftGYDataList)
				})
				var that = this
				this.$httpRequest({
					url: `MES/MESProductionInto/ChangeChildrenProcess`,
					method: 'post',
					data: checkChildrenList
				}).then(function(response) {
					if (response.status == 1) {
						that.$message.success('编辑子工单工艺信息成功')
						that.gyDialogVisable = false
					} else {
						that.$message.error('编辑子工单工艺信息失败')
					}
				})
			},
			openAddOrEditGYDialog(item) {

				if (item != null) {
					this.isAddOrEditGYModel = true
					this.addOrEditGYModel = item
				} else {
					this.isAddOrEditGYModel = false
					this.addOrEditGYModel = {}
				}
				this.addOrEidtGYDialogVisable = true
			},
			//添加或修改工艺
			AddOrEditGY() {
				if (this.isAddOrEditGYModel) {
					this.leftGYDataList.forEach(r => {
						if (r.code + r.name == this.addOrEditGYModel.code + this.addOrEditGYModel.name) {
							r = this.addOrEditGYModel
						}
					})
				} else {
					this.leftGYDataList.push(this.addOrEditGYModel)
				}
				this.addOrEidtGYDialogVisable = false
			},
			//取消编辑或修改
			cancelGY() {
				this.addOrEidtGYDialogVisable = false
				this.addOrEditGYModel = {}
				this.$refs.form.reset()
				// this.childrenOrderList.forEach(r=>{
				// 	r.check=false
				// })
			},
			//选中上面的子工单
			checkChildrenOrderEvent(items) {
				this.currentCheckChildrenOrderList = items
				// var temp = this.currentCheckChildrenOrderList.filter(r => r.id == item.id)
				// if (temp.length <= 0) {
				// 	this.currentCheckChildrenOrderList.push(item)
				// }
			},
			//打开打印对话框
			async openPrintDialog(item) {
				this.printDialog = true
				this.currentPrintSingleModel = item

				// 如果当前子工单不是投产状态，则需要投产
				var response = await this.$httpRequest({
					url: `MES/MESProductionInto/OrderPrint`,
					method: 'post',
					data: {
						childrenIds: [item.id],
						splitBatchCount: 0
					}
				})

				if (response.status == 1) {
					this.currentPrintSingleModel = response.data.cardList[0]
					this.currentPrintSingleModel.requestOrderList = response.data.requestList.data.data
					console.log(this.currentPrintSingleModel.requestOrderList)
				} else {
					this.$message.error(response.info)
				}

			},
			printContext() {
				printJS({
					printable: 'printProcessCard',
					type: 'html',
					targetStyles: ['*'],
					ignoreElements: ['no-print'],
				})


			},
			// 关闭
			close() {
				this.printDialog = false
			},
			getHeader() {
				this.childrenHeaderList = [{
						text: '操作',
						align: 'center',
						value: 'actions',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '子工单号',
						align: 'center',
						value: 'code',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '是否投产',
						align: 'center',
						value: 'isinpruduction',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '是否打印',
						align: 'center',
						value: 'isprint',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '图号',
						align: 'left',
						value: 'piccode',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '文件',
						align: 'center',
						value: 'picurl',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '名称',
						align: 'center',
						value: 'name',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '规格型号',
						align: 'left',
						value: 'specifications',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '需求总数',
						align: 'center',
						value: 'totalcount',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '单位',
						align: 'center',
						value: 'unit',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '交期',
						align: 'center',
						value: 'deliverydate',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '类型',
						align: 'center',
						value: 'typename',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '状态',
						align: 'center',
						value: 'statusname',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '备注',
						align: 'center',
						value: 'description',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '流程卡号',
						align: 'center',
						value: 'temp1',
						filterable: false,
						class: 'fixed'
					},
				]
			},
		},
	}
</script>

<style scoped>
	@import url("../../../../../public/css/print.css");
</style>
